home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / STRINGS.SWG / 0001_Assembler to get String Length.pas next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  862 b   |  38 lines

  1. {
  2.  JP> How do you get the length of a string using assembler? I've tried
  3.  JP> this, but it doesn't work. I was told the first two bytes hold the
  4.  JP> string length. Is this correct?
  5. }
  6.  
  7. function len(s : string) : byte; assembler;
  8. asm
  9.   les di,s
  10.   mov al,es:byte ptr [di]
  11. end;
  12.  
  13. or this:
  14.  
  15. function len(s : string) : byte; assembler;
  16. asm
  17.   push ds
  18.   lds si,s
  19.   mov al,byte ptr [si]
  20.   pop ds
  21. end;
  22.  
  23. {PETER LOUWEN,Re: Assembler to get leng}
  24.  
  25. FUNCTION Len1(CONST Str: STRING): byte; ASSEMBLER;
  26. ASM push ds
  27.     lds si, Str   { -- DS:SI now holds @Str. }
  28.     lodsb         { -- AL := (DS:SI)^.       }
  29.     pop ds
  30. END;
  31.  
  32. FUNCTION Len2(CONST Str: STRING): byte; ASSEMBLER;
  33. ASM les di, Str         { -- ES:DI now holds @Str. }
  34.     mov al, es:[di]     { -- AL := (ES:DI)^.       }
  35. END;
  36.  
  37. The second method is slightly faster on my machine.
  38.